<template>
  <div class="h100">
    <s-table
      class="h100"
      :columns="columns"
      :data="loadData"
      rowKey="id"
      ref="table"
      :scrollX="800">
      <template slot-scope="text" v-for="column in commonColumns" :slot="column.scopedSlots.customRender">
        <table-ellipsis :text="text || '-'" :key="column.key"></table-ellipsis>
      </template>
      <template #releaseNote="text, record">
        <a @click="publishDesc(record)">{{ $t('view') }}</a>
      </template>
    </s-table>
    <!-- 版本的发布说明 -->
    <view-release-note ref="releaseNote" :width="610" :releaseNotes="releaseNotes || {}">
    </view-release-note>
  </div>
</template>
<script>
import { relatedVersionTbColumns } from '../config/list'
import TableEllipsis from '@/components/Ellipsis/TableEllipsis'
import ViewReleaseNote from '@/views/components/ViewReleaseNote'
import { STable } from '@/components'
import { mapState } from 'vuex'
export default {
  components: {
    ViewReleaseNote,
    TableEllipsis,
    STable
  },
  props: {
    ecuModuleId: {
      type: String,
      default: ''
    }
  },
  computed: {
    ...mapState({
      instantUpdateTime: (state) => state.app.instantUpdateTime
    }),
    commonColumns () {
      return relatedVersionTbColumns.filter((item) => !item.special)
    }
  },
  watch: {
    instantUpdateTime: {
      handler () {
        this.refreshData(true)
      },
      immediate: true
    }
  },
  data () {
    return {
      columns: relatedVersionTbColumns,
      // 版本的发布版本数据
      releaseNotes: null
    }
  },
  methods: {
    loadData (parameter) {
      const vm = this
      // 如果是全部则不传值给后端
      const JnqueryParam = {}
      JnqueryParam.ecuModuleId = vm.ecuModuleId
      return vm.$api.getVersionList({ ...parameter, ...JnqueryParam })
    },
    refreshData (bool = false) {
      this.$refs.table && this.$refs.table.refresh(bool)
    },
    //  展示版本的发布说明弹框
    publishDesc (data) {
      this.releaseNotes = {
        description: data.description,
        functionAddition: data.functionAddition,
        functionOptimization: data.functionOptimization,
        acknowledgements: data.acknowledgements
      }
      this.$refs.releaseNote.visible = true
    }
  }
}
</script>
<style lang="less" scoped></style>
